package com.hx.springboot1.dao;

import com.hx.springboot1.pojo.dto.TeacherDTO;
import com.hx.springboot1.pojo.entity.TabTeacher;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Author: hx
 * Date: 2021-05-14 16/33
 * Description: Nothing else
 */
@Repository
@Mapper
public interface TeacherDao {
    @Select("select * from tab_teacher where user_id = #{id}")
    TabTeacher selectByUserId(int id);
    @Select("select * from tab_teacher where teacher_id = #{id}")
    TabTeacher selectByTeacherId(int id);
    @Select("select teacher_id,user_id,college_name,teacher_name,teacher_sex,teacher_job,teacher_qua,teacher_born from tab_teacher a\n" +
            "join tab_college b on a.college_id=b.college_id")
    List<TeacherDTO> selectAllTeacher();
    @Select("select teacher_id,user_id,college_name,teacher_name,teacher_sex,teacher_job,teacher_qua,teacher_born from tab_teacher a\n" +
            "join tab_college b on a.college_id=b.college_id WHERE teacher_name like #{name}")
    List<TeacherDTO> selectAllTeacherByName(String name);
    @Insert("insert into tab_teacher(user_id,college_id,teacher_name,teacher_sex,teacher_job,teacher_qua,teacher_born)\n" +
            "values\n" +
            "(#{userId},#{collegeId},#{teacherName},#{teacherSex},#{teacherJob},#{teacherQua},#{teacherBorn})")
    void insertTeacher(Integer userId,
                       Integer collegeId,String teacherName,String teacherSex,String teacherJob,String teacherQua,String teacherBorn);
    @Update("update tab_teacher set college_id = #{collegeId},teacher_name = #{teacherName},teacher_sex = #{teacherSex},teacher_job = #{teacherJob},\n" +
            "teacher_qua = #{teacherQua},teacher_born = #{teacherBorn} where teacher_id = #{teacherId}")
    void updateTeacher(Integer teacherId,
                       Integer collegeId,String teacherName,String teacherSex,String teacherJob,String teacherQua,String teacherBorn);
    @Delete("delete from tab_teacher where teacher_id = #{tId}")
    int delTeacher(int tId);
}
